From f90beca56ee0d103f31928ec83d6d08bdce24b4b Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Tue, 21 Nov 2006 11:21:20 +0000 Subject: [PATCH] Added an xm console -q flag. Signed-off-by: Ewan Mellor --- tools/python/xen/xm/main.py | 44 ++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py index da664189d9..46679b5d0e 100644 --- a/tools/python/xen/xm/main.py +++ b/tools/python/xen/xm/main.py @@ -67,7 +67,7 @@ USAGE_FOOTER = ' can either be the Domain Name or Id.\n' \ SUBCOMMAND_HELP = { # common commands - 'console' : ('', + 'console' : ('[-q|--quiet] ', 'Attach to \'s console.'), 'create' : (' [options] [vars]', 'Create a domain based on .'), @@ -190,6 +190,9 @@ SUBCOMMAND_OPTIONS = { ('-l', '--long', 'Output all VM details in SXP'), ('', '--label', 'Include security labels'), ), + 'console': ( + ('-q', '--quiet', 'Do not print an error message if the domain does not exist'), + ), 'dmesg': ( ('-c', '--clear', 'Clear dmesg buffer'), ), @@ -1002,15 +1005,46 @@ def xm_info(args): print "%-23s:" % x[0], x[1] def xm_console(args): - arg_check(args, "console", 1) + arg_check(args, "console", 1, 2) - dom = args[0] - info = server.xend.domain(dom) + quiet = False; + + try: + (options, params) = getopt.gnu_getopt(args, 'q', ['quiet']) + except getopt.GetoptError, opterr: + err(opterr) + sys.exit(1) + + for (k, v) in options: + if k in ['-q', '--quiet']: + quiet = True + else: + assert False + + if len(params) != 1: + err('No domain given') + usage('console') + sys.exit(1) + + dom = params[0] + + try: + info = server.xend.domain(dom) + except: + if quiet: + sys.exit(1) + else: + raise domid = int(sxp.child_value(info, 'domid', '-1')) if domid == -1: - raise Exception("Domain is not started") + if quiet: + sys.exit(1) + else: + raise Exception("Domain is not started") + console.execConsole(domid) + def xm_uptime(args): short_mode = 0 -- 2.30.2